package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.IncomeBankBean;
import com.koron.css2.baseConfig.mapper.IncomeBankMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class IncomeBankAdd implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            IncomeBankMapper mapper = factory.getMapper(IncomeBankMapper.class);
            IncomeBankBean bean = JsonUtils.objectToPojo(req.getData(), IncomeBankBean.class);
            String userName = userInfo.getUserInfo().getName();
            String account = userInfo.getUserInfo().getAcount();
            String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            bean.setId(UUID.randomUUID().toString().replace("-",""));
            bean.setCreateAccount(account);
            bean.setCreateName(userName);
            bean.setCreateTime(nowTime);
            bean.setModifyAccount(account);
            bean.setModifyName(userName);
            bean.setModifyTime(nowTime);
            mapper.insert(bean);
            MessageBean<?> msg = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", Void.class);
            return msg;
        } catch (Exception e) {
            logger.error("添加进账银行信息失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "添加进账银行信息失败", void.class);
        }
    }
}
